﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace TreasureHunter
{
    public class Square
    {
        public const int Size = 80;
        private Board board;
        public Bitmap Texture;
        public bool IsFixed = false;
        public bool North { get; set; }
        public bool East { get; set; }
        public bool South { get; set; }
        public bool West { get; set; }
        public int X;
        public int Y;

        public Square(Board gameBoard, bool isNorthOpen, bool isEastOpen, bool isSouthOpen, bool isWestOpen)
        {
            this.board = gameBoard;
            this.North = isNorthOpen;
            this.East = isEastOpen;
            this.South = isSouthOpen;
            this.West = isWestOpen;
            this.Texture = TextureLoader.GetMatchingTexture(North, East, South, West);
        }
        public Square(bool isFixed, Board gameBoard, bool isNorthOpen, bool isEastOpen, bool isSouthOpen, bool isWestOpen) 
            : this(gameBoard, isNorthOpen, isEastOpen, isSouthOpen, isWestOpen)
        {
            this.IsFixed = isFixed;
        }

        /// <summary>
        /// Places the card on the board on a specific position.
        /// </summary>
        /// <param name="xIndex">X-Index in the grid on the board where the card is placed.</param>
        /// <param name="yIndex">X-Index in the grid on the board where the card is placed.</param>
        public void Place(int xIndex, int yIndex)
        {
            this.board.PlaceCardOnBoard(this, xIndex, yIndex); //Place this card on the board on this position.
            this.X = xIndex;
            this.Y = yIndex;
        }

        /// <summary>
        /// Draws the Card.
        /// </summary>
        /// <param name="e"></param>
        public void Draw(PaintEventArgs e)
        {
            int drawPosX = X * Size;
            int drawPosY = Y * Size;
            e.Graphics.DrawImage(this.Texture, new Rectangle(drawPosX, drawPosY, Square.Size, Square.Size));
        }


    }
}
